<template>
	<section>
		<header class="hei100 wallfff rela own-h">
			<a href="javascript: history.back()" class="_h">
				<i class="icon-Goback"></i>
			</a>
			<h1 class="flex_core  hei100 sz34 fontwt">
				{{txt}}
			</h1>
			<router-link :to="{path:'/ownAll/record',query:{type:$route.query.type}}" class="hued44 sz30 h_">
				{{txt}}记录
			</router-link>
		</header>
		<a href="javascript: void(0)" class="flex_between wallfff p30 mu20 sz30" v-if="$route.query.type!=='point'" @click="getBank">
			<span>银行卡：</span>
			<p class="flex1">{{BankID.MembersBank_Account}}</p>
			<i class="icon-advance"></i>
		</a>

		<p class="p30 sz20" v-if="$route.query.type==='point'">当前可转化积分：<strong>{{Number(asset.Asset_Points).toFixed(2)}}</strong></p>
		<p class="p30 sz20" v-else>当前可提现金额：<strong>{{Number(asset.Asset_Fund).toFixed(2)}}</strong>元</p>
		<div class="flexs plr30 wallfff">
			<label class="sz28 flex_self plr30">金额：</label>
			<input class="hei100 flex1 sz28" v-model="num" type="number" placeholder="请输入" />
		</div>
		<button type="button" class="btns" @click="sure">确认</button>
		<mt-popup v-model="bankflag" position="bottom" closeOnClickModal="false" class="w100">
			<h1 class="centre p30 bbtm sz28 fontwt">选择银行卡</h1>
			<ul class="bank_ul" v-if="bank">
				<li v-for="(item,index) in bank" class="pud20 bbtm sz30 centre" @click="setBank(index)">
					{{item.Bank_Name}} {{item.MembersBank_Account}}
				</li>
			</ul>
			<router-link to="/ownAll/bankcard" class="flex_core sz28 hued44 pud20">
				添加银行卡
			</router-link>
		</mt-popup>
	</section>
</template>

<script>
	import { MessageBox } from 'mint-ui';
	import { Popup } from 'mint-ui';
	import { Toast } from 'mint-ui';
	import { Indicator } from 'mint-ui';
	import Qs from 'qs';
	import md5 from 'js-md5';
	export default {
		data() {
			return {
				bank: [],
				bankflag: false,
				txt: this.$route.query.type === "point" ? "转化" : "提现",
				asset: JSON.parse(sessionStorage.asset),
				num: "",
				BankID: {
					MembersBank_Account: "请选择银行卡",
					MembersBank_ID: ""
				}
			}
		},
		methods: {
			getBank: function() {
				let v = this;
				v.bankflag = true;
				if(!sessionStorage.bank) {
					Indicator.open();
					v.$http.get("/WorkMembersAsset/v1.0/GetMembersBank", {
						params: {
							MembersID: sessionStorage.MembersID
						}
					}).then((res) => {
						Indicator.close();
						if(!res.data.Return_ID) {
							let resdata = res.data.Return_Data;
							if(!resdata || !resdata.length) {
								v.bank = null;
								return false;
							}
							v.bank = res.data.Return_Data;
							sessionStorage.bank = JSON.stringify(res.data.Return_Data);
						} else {
							Toast(res.data.Return_Mess)
						}
					});
				} else {
					v.bank = JSON.parse(sessionStorage.bank);
				}
				console.log(v.bank)
			},
			setBank: function(index) {
				let v = this;
				v.BankID = v.bank[index];
				v.bankflag = false;
			},
			sure: function() {
				let v = this;
				if(!JSON.parse(sessionStorage.infos).Members_HasPayPwd) {
					MessageBox.confirm('没有支付密码，确认前去设置').then(action => {
						if(action === "confirm") {
							v.$router.push("/ownAll/setpwd?types=pay");
						}
					});
					return
				}
				if(v.$route.query.type !== "point") {
					if(!v.BankID.MembersBank_ID) {
						Toast("请选择银行卡");
						return
					}
				}
				if(!Number(v.num) > 0) {
					Toast("请输入有效金额");
				} else {
					MessageBox.prompt("","",{
						message: '请输入密码',
						showCancelButton: true,
						showInput: true,
						inputType: "password",
					})
					.then((res) => {
						let vals = res.value;
						if(/^\d{6}$/.test(vals)) {
							if(v.$route.query.type === "point") {
								v.point(vals);
							} else {

								v.cash(vals);
							}
						} else {
							Toast("请输入6位支付密码");
						}
					});

				}
			},
			point: function(vals) {
				let v = this;
				Indicator.open();
				v.$http.post("/WorkMembersAsset/V1.0/PointTransform", Qs.stringify({
					"MembersID": sessionStorage.MembersID,
					"TransformMoney": v.num,
					"PayPwd": md5(vals)
				})).then((res) => {
					Indicator.close();
					Toast(res.data.Return_Mess);
					if(!res.data.Return_ID) {
						v.$router.back();
					}
				})
			},
			cash: function(vals) {
				let v = this;
				Indicator.open();
				v.$http.post("/WorkMembersAsset/V1.0/FundDraw", Qs.stringify({
					"MembersID": sessionStorage.MembersID,
					"DrawMoney": v.num,
					"PayPwd": md5(vals),
					"BankID": v.BankID.MembersBank_ID
				})).then((res) => {
					Indicator.close();
					Toast(res.data.Return_Mess);
					if(!res.data.Return_ID) {
						v.$router.back();
					}
				})
			}
		}

	}
</script>

<style>

</style>